#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QAudioOutput>
#include <QListWidget>
#include <QSlider>
#include <QLabel>
#include <QPushButton>
#include <QFileDialog>
#include <QStringList>
#include <QTimer>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_pauseBtn_clicked();
    void on_preBtn_clicked();
    void on_nextBtn_clicked();
    void on_listBtn_clicked();
    void on_mediaListWidget_itemDoubleClicked(QListWidgetItem *item);
    void updateProgress();
    void updateDuration(qint64 duration);
    void updatePosition(qint64 position);
    void on_progressSlider_sliderMoved(int position);

private:
    Ui::MainWindow *ui;
    QMediaPlayer *mediaPlayer;
    QVideoWidget *videoWidget;
    QAudioOutput *audioOutput;
    QStringList mediaFiles;
    int currentIndex;
    QTimer *progressTimer;
    
    void setupMediaPlayer();
    void loadMediaFile(const QString &filePath);
    void updateTimeLabel(qint64 position, qint64 duration);
    QString formatTime(qint64 ms);
    bool isVideoFile(const QString &filePath);
};
#endif // MAINWINDOW_H
